<?php

namespace app\api\controller;

use app\common\exception\BusinessException;
use think\response\Json;

class Vip extends Base
{
    /**
     * 充值信息
     * @return Json
     * @throws
     */
    public function chargeInfo(): Json
    {
        // 请求参数
        $param = $this->request->param();

        // 查询价格
        $result = (new \app\api\logic\Vip())->chargeInfo($param);

        // 返回数据
        return $this->response($result);
    }

    /**
     * 转让信息
     * @return Json
     * @throws
     */
    public function transferInfo(): Json
    {
        // 请求参数
        $param = $this->request->param();

        // 查询价格
        $result = (new \app\api\logic\Vip())->transferInfo($param);

        // 返回数据
        return $this->response($result);
    }

    /**
     * 转让会员
     * @return Json
     * @throws BusinessException
     */
    public function transfer(): Json
    {
        // 请求参数
        $param = $this->request->param();

        // 验证规则
        $rule = [
            'uid' => 'require',
            'vid' => 'require',
        ];

        // 错误信息
        $errMsg = [
            'uid.require' => '请填写对方会员编号',
            'vid.require' => '请选择转让会员信息',
        ];

        // 数据验证
        $valRel = $this->validate($param, $rule, $errMsg);
        if ($valRel !== true) {
            throw new BusinessException($valRel, 0);
        }

        // 确认转让
        (new \app\api\logic\Vip())->transfer($param);

        // 返回数据
        return $this->response();
    }
}
